package logic

import (
	"context"
	"shop_srv/goods"

	"api/internal/svc"
	"api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type GetGoodsListLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewGetGoodsListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetGoodsListLogic {
	return &GetGoodsListLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *GetGoodsListLogic) GetGoodsList(req *types.GetGoodsListRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	getGoods, err := l.svcCtx.GoodsSrv.GetGoods(l.ctx, &goods.GetGoodsRequest{
		Page: req.Page,
		Size: req.Size,
	})
	if err != nil {
		return &types.Response{
			Code:    -1,
			Message: "服务器内部错误",
			Data:    nil,
		}, nil
	}
	l.svcCtx.GoodsSrv.GetGoodsSearch(l.ctx, &goods.GetGoodsSearchRequest{GoodsTitle: ""})
	return &types.Response{
		Code:    0,
		Message: "列表查询成功",
		Data: map[string]interface{}{
			"getGoods": getGoods,
		},
	}, nil
}
